<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        小区管理
    </title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="telephone=no" name="format-detection">
    <link href="css/main.css" media="all" rel="stylesheet">
    <script src="lib/loading/okLoading.js" type="text/javascript"></script>
    <!--百度编辑器-->
    <script src="ueditor/ueditor.config.js"></script>
    <script src="ueditor/ueditor.all.min.js"></script>
    <script src="ueditor/lang/zh-cn/zh-cn.js"></script>

</head>
<style>
    .imgs {
        display: none;
    }

    .picture {
        display: none;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>小区管理</cite></a>
              <a><cite>添加小区</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);"
       style="line-height:1.6em;margin-top:3px;float:right" title="刷新"><i class="layui-icon"
                                                                            style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form action="" class="layui-form layui-form-pane" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <!--<ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
                <li>SEO信息</li>
                <li>栏目内容</li>
            </ul>-->

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <!--<form class="layui-form layui-form-pane" action="" id="add">-->
                    <input name="id" type="hidden" value="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>小区管理员
                        </label>
                        <div class="layui-input-block">
                            <select id="user_id" name="user_id">

                                <option value="4">admin</option>
                                <option value="5">admin</option>
                                <option value="6">admin</option>
                                <option value="7">admin</option>
                                <option value="8">ADMIN</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>小区名称
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="community_name"
                                   placeholder="小区名称" required="" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>坐落地址
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="cell_address"
                                   placeholder="坐落地址" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>占地面积
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="area_covered"
                                   placeholder="占地面积" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>开发商名称
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="developers"
                                   placeholder="开发商名称" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>物业公司名称
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="property"
                                   placeholder="物业公司名称" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>绿化率
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required"
                                   name="afforestation_rate"
                                   placeholder="绿化率" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>总栋数
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="tung"
                                   placeholder="总栋数" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>总户数
                        </label>
                        <div class="layui-input-block">
                            <input autocomplete="off" class="layui-input" lay-verify="required" name="household"
                                   placeholder="总户数" type="text" value="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>状态
                        </label>
                        <div class="layui-input-block">
                            <input name="status" title="显示" type="radio" value="1">
                            <div class="layui-unselect layui-form-radio layui-form-radioed"><i
                                    class="layui-anim layui-icon layui-anim-scaleSpring"></i>
                                <div>显示</div>
                            </div>
                            <input checked="checked" name="status" title="隐藏" type="radio" value="0">
                            <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                                <div>隐藏</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="link">
                            <span class="x-red">*</span>小区缩略图
                        </label>
                        <div class="layui-input-inline">
                            <div class="site-demo-upbar">
                                <div class=" layui-upload-button" style="border:#FFFFFF ;">
                                    <button class="layui-btn" id="test1" type="button">
                                        <i class="layui-icon">&#xe67c;</i>上传图片
                                    </button>
                                    <input accept="undefined" class="layui-upload" id="previewImg" name="images"
                                           onchange="upload(this,)" type="file">
                                </div>

                            </div>
                        </div>

                        <!--<a href="javascript:;" style="" class="layui-btn " id="cancel"><i class="layui-icon">ဂ</i>撤销上传</a>-->
                    </div>
                    <div class="layui-form-item imgs" id="imgshow">
                        <label class="layui-form-label">小区缩略图展示
                        </label>
                        <img id="pimages" name="pimages" src="" style="width: 400px;height: 200px;"/>
                        <input id="avatar" name="image" required="" type="hidden" value="">
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label" for="link">
                            <span class="x-red">*</span>小区简介
                        </label>
                        <div class="layui-input-inline">
                            <textarea id="content" name="desc" placeholder=""></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" lay-filter="add" lay-submit="" type="button">
                            保存
                        </button>
                    </div>
                    <!--</form>-->
                    <div style="height:100px;"></div>
                </div>


            </div>

        </div>
    </form>
</div>
<script charset="utf-8" src="lib/layui/layui.js"></script>
<script charset="utf-8" src="js/x-layui.js"></script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('content', {initialFrameWidth: 700, initialFrameHeight: 200,});
</script>
<script>
    layui.use(['element', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        okLoading.close($);

        //监听提交
        form.on('submit(add)', function (data) {
            var community_name = $("input[name='community_name']").val();
            var developers = $("input[name='developers']").val();
            var property = $("input[name='property']").val();
            if (community_name == "") {
                layer.msg('小区名称不能为空', {icon: 5, time: 2000});
                return false;
            }
            if (developers == "") {
                layer.msg('小区开发商不能为空', {icon: 5, time: 2000});
                return false;
            }
            if (property == "") {
                layer.msg('物业公司不能为空', {icon: 5, time: 2000});
                return false;
            }
            var data = data.field;
            $.ajax({
                type: "post",
                url: "/xiyuan/community/add.html",
                data: data,
                dataType: "json",
                success: function (data) {
                    //alert(1);
                    if (data.status == 1) {
                        layer.msg(data.info, {icon: 6, time: 2000}, function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;

                    } else {
                        layer.msg(data.info, {icon: 5, time: 2000});
                        return false;
                    }
                }

            });

        });

    })
</script>
<!--栏目缩略图上传-->
<script>
    function upload(obj, id) {
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        formData.append('id', id);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type: "post",
            processData: false,
            contentType: false,
            url: "/xiyuan/community/upload.html",
            data: formData,
            success: function (data) {
                if (data.status == 1) {
                    //console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src', data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                } else {
                    layer.msg(data.info, {icon: 2, time: 1000});
                }
            }
        });
    }
</script>

</body>
</html>